package com.gable.report.service.impl;

import com.gable.report.common.util.MonthEnumUtil;
import com.gable.report.dao.IChartsForAssetsOverviewDao;
import com.gable.report.model.ChartsForAssetsOverview;
import com.gable.report.service.ChartsForAssetsOverviewService;
import com.gable.report.util.ChartsUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lvdouStart on 2017/12/4.
 *
 */
@Service
public class ChartsForAssetsOverviewServiceImpl implements ChartsForAssetsOverviewService {

    @Autowired
    private IChartsForAssetsOverviewDao chartsForAssetsOverviewDao;

    private final Log logger = LogFactory.getLog(this.getClass());


    @Override
    public ChartsForAssetsOverview queryAssetsFieldsOverview(Long deviceId) {
        Map<String,Object> paramMap = new HashMap();
        paramMap.put("deviceId",deviceId);
        ChartsUtil.dateProcess(null,null,paramMap);
        ChartsForAssetsOverview cfao = chartsForAssetsOverviewDao.queryAssetsFieldsOverview(paramMap);
        return cfao;
    }

    @Override
    public List<ChartsForAssetsOverview> queryAssetsPerformanceByMonth(Long deviceId) {
        Map<String,Object> paramMap = new HashMap();
        paramMap.put("deviceId",deviceId);
        ChartsUtil.dateProcess(null,null,paramMap);
        //月份报表，去年的全部显示，处理去年日期区间
        int curYear = (Integer) paramMap.get("curYear");
        paramMap.put("lastYearEnd",new StringBuffer().append("'").append(curYear).append("-1-1").append("'").toString());
        List<ChartsForAssetsOverview> list = chartsForAssetsOverviewDao.queryAssetsPerformanceByMonth(paramMap);
        //设置中文月份名称
        for(ChartsForAssetsOverview obj : list){
            obj.setName(MonthEnumUtil.getValue(obj.getId()+""));
        }
        return list;
    }

    @Override
    public List<ChartsForAssetsOverview> queryAssetsPerformanceByYear(Long deviceId) {
        return chartsForAssetsOverviewDao.queryAssetsPerformanceByYear(deviceId);
    }

    @Override
    public List<ChartsForAssetsOverview> queryAssetsRepairInfoByMonth(Long deviceId) {
        Map<String,Object> paramMap = new HashMap();
        paramMap.put("deviceId",deviceId);
        ChartsUtil.dateProcess(null,null,paramMap);
        //月份报表，去年的全部显示，处理去年日期区间
        int curYear = (Integer) paramMap.get("curYear");
        paramMap.put("lastYearEnd",new StringBuffer().append("'").append(curYear).append("-1-1").append("'").toString());
        //设置中文月份名称
        List<ChartsForAssetsOverview> list = chartsForAssetsOverviewDao.queryAssetsRepairInfoByMonth(paramMap);
        for(ChartsForAssetsOverview obj : list){
            obj.setName(MonthEnumUtil.getValue(obj.getId()+""));
        }
        return list;
    }

    @Override
    public List<ChartsForAssetsOverview> queryAssetsRepairInfoByYear(Long deviceId) {
        return chartsForAssetsOverviewDao.queryAssetsRepairInfoByYear(deviceId);
    }

    @Override
    public Map<String, Object> queryOperationRadar(Long deviceId) {
        return chartsForAssetsOverviewDao.queryOperationRadar(deviceId);
    }
}
